package com.itheima.app.manager;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.domain.mongo.Video;
import com.itheima.service.mongo.VideoService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 对视频的操作，发送MQ消息到中间件
 */
@Component
public class MQVideoManager {

    //针对动态的操作
    public static final Integer VIDEO_PUBLISH = 1;// 发视频
    public static final Integer VIDEO_LIKE = 2;// 点赞
    public static final Integer VIDEO_DISLIKE = 3;// 取消点赞
    public static final Integer VIDEO_COMMENT = 4;// 评论视频
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Reference
    private VideoService videoService;

    //针对视频的操作
    public void sendVideoMsg(String videoId, Integer type) {
        //根据视频id查询视频详情videoId
        Video video = videoService.findByVideoId(videoId);

        //构建MQ消息内容
        Map<String, Object> map = new HashMap<>();
        map.put("vid", videoId);
        map.put("uid", UserHolder.getId());
        map.put("type", type);
        rocketMQTemplate.convertAndSend("tanhua-recommend-video",map);

    }
}
